<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class APwColonysArticleModel extends Model {
   /*public function getTodayArticleNum($cyid){//根据群组id获取当前主题数
      $from=date('Y-m-d');
      $to=$from." 23:59:59";
      $num=$this->where("cyid={$cyid} and create_time>={$from} and create_time<={$to}")->count();
      return $num?$num:0;
   }*/
   
   /*
    * 根据群组id返回主题数(type=1)/帖子数(type=2)/当天主题数(type=3)
    */
   public function getArticleNum($cyid,$type=1){
     
	 if($type==1)$map["cyid"]=array('eq',$cyid);
	 if($type==3){
	   $from=date('Y-m-d');
       $to=$from." 23:59:59";
       $todayNum=$this->where("cyid={$cyid}  and ((a_pw_colonys_article_comment.create_time>='{$from}' and a_pw_colonys_article_comment.create_time<='{$to}') 
	                          or (a_pw_colonys_article.create_time>='{$from}' and a_pw_colonys_article.create_time<='{$to}'))")
	                  ->join("a_pw_colonys_article_comment on a_pw_colonys_article.id=a_pw_colonys_article_comment.aid")
					  ->count();
       //xit($this->getLastSQL());
	   return $todayNum; 
	  }
	  
	 elseif($type==1){
	    $map['_string']="cyid={$cyid}";
	    $articleNum=$this->where($map)->count();
        return $articleNum;
		}else{
        $commentNum=$this->where("cyid={$cyid}")
		                 ->join("a_pw_colonys_article_comment on a_pw_colonys_article.id=a_pw_colonys_article_comment.aid")
		                 ->count();
        return $commentNum;
     }
   }

}
?>
